package com.igeek.boot.mapper;

import com.igeek.boot.entity.Orders;
import com.igeek.boot.entity.UserCustom;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserAndOrderMapper {
    //1）.根据订单号查询 用户姓名
    @Select("select name from user where id = (select user_id from orders where id = #{value})")
    public String getUsernameByOrderId(Integer id);
    //2）.根据用户id查询 所属用户的订单有哪些?
    @Select("select * from user where id = #{value}")
    @Results(value = {
            @Result(property = "id",column = "id"),
            @Result(
                    property = "ordersList",
                    column = "id",
                    javaType = java.util.List.class,
                    many = @Many(select = "com.igeek.boot.mapper.UserAndOrderMapper.getOrdersById"))
    })
    public UserCustom getUserAndOrdersByUserId(Integer id);

    @Select("select * from orders where user_id = #{value}")
    @Results(value = {
            @Result(property = "id",column = "id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "number",column = "number"),
            @Result(property = "createtime",column = "createtime"),
            @Result(property = "note",column = "note")
    })
    public List<Orders> getOrdersById(Integer id);
}
